#ifndef _MEDIA_SINK_H_
#define _MEDIA_SINK_H_

#include <string>
#include <arpa/inet.h>
#include "Rtp.h"


class RtpSink
{
public:
    typedef void (*SendPacketCallback)(void* arg1, void* arg2, RtpPacket* mediaPacket);

    virtual ~RtpSink();

    virtual std::string getMediaDescription(uint16_t port) = 0;
    virtual std::string getAttribute() = 0;

    void setSendFrameCallback(SendPacketCallback cb, void* arg1, void* arg2);

protected:
    // virtual void handleFrame(AVFrame* frame) = 0;
    void sendRtpPacket(RtpPacket* packet) 
    {
        RtpHeader* rtpHead = packet->mRtpHeader;
        rtpHead->csrcLen = mCsrcLen;
        rtpHead->extension = mExtension;
        rtpHead->padding = mPadding;
        rtpHead->version = mVersion;
        rtpHead->payloadType = mPayloadType;
        rtpHead->marker = mMarker;
        rtpHead->seq = htons(mSeq);
        rtpHead->timestamp = htonl(mTimestamp);
        rtpHead->ssrc = htonl(mSSRC);
        packet->mSize += RTP_HEADER_SIZE;
        
        if(mSendPacketCallback)
            mSendPacketCallback(mArg1, mArg2, packet);
    }
    // void start(int ms);
    // void stop();

    SendPacketCallback mSendPacketCallback;
    void* mArg1;
    void* mArg2;

    uint8_t mCsrcLen;
    uint8_t mExtension;
    uint8_t mPadding;
    uint8_t mVersion;
    uint8_t mPayloadType;
    uint8_t mMarker;
    uint16_t mSeq;
    uint32_t mTimestamp;
    uint32_t mSSRC;

private:
    static void timeoutCallback(void*);
};

#endif //_MEDIA_SINK_H_